package com.zhkj.shixi.tvplayer.banner.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;


public class BannerViewPager extends ViewPager {
    private static final String TAG = "BannerViewPager";
    private boolean scrollable = true;

    public boolean isScrollable() {
        return scrollable;
    }

    public BannerViewPager(Context context) {
        super(context);
    }

    public BannerViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
//        Log.i(TAG, "dispatchKeyEvent: ssss" + event.getAction()  + " scrollable =" + this.scrollable);

        if(this.scrollable) {

            if (getCurrentItem() == 0 && getChildCount() == 0) {
                return false;
            }
            return super.executeKeyEvent(event);
        } else {
            return false;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.e("cnk","rrrrrrrrrrrrrrrrrrr");
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean executeKeyEvent(KeyEvent event) {
//        Log.i(TAG, "dispatchKeyEvent: ssss" + event.getAction()  + " scrollable =" + this.scrollable);
        if(this.scrollable) {
            if (getCurrentItem() == 0 && getChildCount() == 0) {
                return false;
            }
            return super.executeKeyEvent(event);
        } else {
            return false;
        }
    }
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if(this.scrollable) {
            if (getCurrentItem() == 0 && getChildCount() == 0) {
                return false;
            }
            return super.onTouchEvent(ev);
        } else {
            return false;
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if(this.scrollable) {
            if (getCurrentItem() == 0 && getChildCount() == 0) {
                return false;
            }
            return super.onInterceptTouchEvent(ev);
        } else {
            return false;
        }
    }

    @Override
    public boolean onKeyLongPress(int keyCode, KeyEvent event) {
        return false;
    }

    public void setScrollable(boolean scrollable) {
        this.scrollable = scrollable;
    }
}
